<template>
  <div class="menu-bar">
    <transition name="slide-up">
      <div class="menu-wapper" :class="{'hide-box-shadow':settingShow || !titleAndMenuShow}" v-show="titleAndMenuShow">
        <div class="icon-wapper">
            <span class="icon-menu icon" @click="showSetting(3)"></span>
        </div>
        <div class="icon-wapper">
            <span class="icon-progress icon" @click="showSetting(2)"></span>
        </div>
        <div class="icon-wapper">
            <span class="icon-brightness icon" @click="showSetting(1)"></span>
        </div>
        <div class="icon-wapper">
            <span class="icon-A icon" @click="showSetting(0)">A</span>
        </div>
      </div>
    </transition>
    <transition name="slide-up">
      <div class="setting-wapper" v-show="settingShow">
        <div class="setting-fontsize" v-if="showTag === 0">
          <div class="preview" :style="{fontSize:fontSizeList[0].fontSize + 'px'}">A</div>
          <div class="select">
            <div class="select-wapper" @click="setFontSize(item.fontSize)" v-for="(item, index) in fontSizeList" :key="index">
              <div class="line"></div>
              <div class="point-wapper">
                <div class="point" v-show="defaultFontSize === item.fontSize">
                  <div class="smallpoint"></div>
                </div>
              </div>
              <div class="line"></div>
            </div>
          </div>
          <div class="preview" :style="{fontSize:fontSizeList[fontSizeList.length-1].fontSize + 'px'}">A</div>
        </div>
        <div class="setting-theme" v-else-if="showTag === 1">
          <div class="setting-theme-item" v-for="(item, index) in themeList" :key="index" @click="setTheme(index)">
            <div class="preview" :style="{background:item.style.body.background}" :class="{'no-border': item.style.body.background != '#fff'}">
            </div>
            <div class="text" :class="{'selected':index === defaultTheme}">{{item.name}}</div>
          </div>
        </div>
        <div class="setting-progress" v-else-if="showTag === 2">
          <div class="progress-wapper">
            <input type="range" class="progress"
                                max="100"
                                min="0"
                                step="1"
                                @change="onProgressChange($event.target.value)"
                                @input="onProgressInput($event.target.value)"
                                :value="progress"
                                :disabled="!bookAvailable"
                                ref="progress"
            >
          </div>
          <div class="text-wapper">
            <span>{{bookAvailable ? progress + '%' : '加载中...'}}</span>
          </div>
        </div>
      </div>
    </transition>
    <content-view :ifShowContent="ifShowContent" v-show="ifShowContent" :navigation="navigation" :bookAvailable="bookAvailable" @jumpTo="jumpTo"></content-view>
    <transition name="fade">
      <div class="content-mask" @click="hideContent" v-show="ifShowContent"></div>
    </transition>
  </div>
</template>

<script>
import ContentView from '@/components/Content'
export default {
  components: {
    ContentView
  },
	props:{
		titleAndMenuShow:{
			type: Boolean,
			default: false
    },
    fontSizeList: Array,
    defaultFontSize: Number,
    themeList: Array,
    defaultTheme: Number,
    bookAvailable: {
      type: Boolean,
      default: false
    },
    navigation: Object
  },
  data() {
    return {
      settingShow: false,
      showTag: 0,
      progress: 0,
      ifShowContent: false
    }
  },
  methods: {
    showSetting(tag) {
      this.showTag = tag
      if (this.showTag === 3) {
        this.settingShow = false
        this.ifShowContent = true
      } else {
        this.settingShow = true
      }
    },
    hideSetting() {
      this.settingShow = false
    },
    setFontSize(fontsize) {
      this.$emit('setFontSize', fontsize)
    },
    setTheme(index) {
      this.$emit('setTheme', index)
    },
    onProgressInput(progress) {
      this.progress = progress
      this.$refs.progress.style.backgroundSize = `${this.progress}% 100%`
    },
    onProgressChange(progress) {
      this.$emit('onProgressChange', progress)
    },
    hideContent() {
      this.ifShowContent = false
    },
    jumpTo(href) {
      this.$emit('jumpTo', href)
    }
  }
}
</script>

<style lang='scss' scoped>
@import '../assets/styles/global';
.menu-bar{
  .menu-wapper{
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 101;
    width: 100%;
    height: px2rem(48);
    background: white;
    box-shadow: 0 px2rem(-8) px2rem(8) rgba(0, 0, 0, .15);
    display: flex;
    .icon-wapper{
        flex: 1;
        @include center;
        .icon-progress{
            font-size: px2rem(22);
        }
        .icon-brightness{
            font-size: px2rem(22);
        }
        .icon-A{
            font-size: px2rem(18);
        }
    }
    &.hide-box-shadow{
      box-shadow: none;
    }
  }
  .setting-wapper{
    position: absolute;
    z-index: 100;
    bottom: px2rem(48);
    left: 0;
    width: 100%;
    height: px2rem(60);
    box-shadow: 0 px2rem(-8) px2rem(8) rgba(0, 0, 0, .15);
    background: white;
    .setting-fontsize{
      display: flex;
      height: 100%;
      .preview{
        flex: 0 0 px2rem(40);
        @include center;
      }
      .select{
        display: flex;
        flex: 1;
        .select-wapper{
          flex: 1;
          display: flex;
          align-items: center;
          &:first-child{
            .line{
              &:first-child{
                border-top: none;
              }
            }
          }
          &:last-child{
            .line{
              &:last-child{
                border-top: none;
              }
            }
          }
          .line{
            flex: 1;
            height: 0;
            border-top: px2rem(1) solid #cccccc;
          }
          .point-wapper{
            flex: 0 0 0;
            height: px2rem(7);
            width: 0;
            border-left: px2rem(1) solid #cccccc;
            position: relative;
            .point{
              position: absolute;
              top: px2rem(-8);
              left: px2rem(-7);
              width: px2rem(20);
              height: px2rem(20);
              border-radius: 50%;
              background: white;
              border: px2rem(1) solid #cccccc;
              box-shadow: 0 px2rem(3) px2rem(4) rgba(0, 0, 0, .15);
              @include center;
              .smallpoint{
                width: px2rem(5);
                height: px2rem(5);
                background: black;
                border-radius: 50%;
              }
            }
          }
        }
      }
    }
    .setting-theme{
      display: flex;
      height: 100%;
      .setting-theme-item{
        flex: 1;
        display: flex;
        flex-direction: column;
        padding: px2rem(5);
        box-sizing: border-box;
        .preview{
          flex: 1;
          border: px2rem(1) solid #ccc;
          box-sizing: border-box;
          &.no-border{
            border: none;
          }
        }
        .text{
          flex: 0 0 px2rem(20);
          font-size: px2rem(14);
          color: #ccc;
          @include center;
          &.selected{
            color: #333;
          }
        }
      }
    }
    .setting-progress{
      width: 100%;
      height: 100%;
      position: relative;
      .progress-wapper{
        width: 100%;
        height: 100%;
        @include center;
        padding: 0 px2rem(30);
        box-sizing: border-box;
        .progress{
          width: 100%;
          -webkit-appearance: none;
          height: px2rem(2);
          background: -webkit-linear-gradient(#999, #999) no-repeat, #ddd;
          background-size: 0 100%;
          &:focus{
            outline: none;
          }
          &::-webkit-slider-thumb{
            -webkit-appearance: none;
            height: px2rem(20);
            width: px2rem(20);
            border-radius: 50%;
            background: white;
            box-shadow: 0 px2rem(4) px2rem(4) 0 rgba(0, 0, 0, .15);
            border: px2rem(1) solid #ddd;
          }
        }
      }
      .text-wapper{
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        color: #333;
        font-size: px2rem(12);
        text-align: center;
      }
    }
  }
  .content-mask{
    position: absolute;
    top: 0;
    left: 0;
    z-index: 101;
    display: flex;
    width: 100%;
    height: 100%;
    background: rgba(51, 51, 51, .8);
  }
}
</style>
